﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sharp.Platform.Mvc
{
    /// <summary>
    /// 模板操作中介
    /// </summary>
    public class TemplateOperateAction
    {
        private static readonly Dictionary<string, Func<object, string>> OperateDictionary = new Dictionary<string, Func<object, string>>();
        public TemplateOperateAction()
        {

        }

        public TemplateOperateAction(string operate)
        {
            
        }

        public void GatherOperate(string operate, Func<object, string> action)
        {
            if (!OperateDictionary.ContainsKey(operate))
                OperateDictionary.Add(operate, action);
        }

        public string ExecuteOperate(string  operate,  object param)
        {
            if (OperateDictionary.ContainsKey(operate))
            {
                return OperateDictionary[operate](param);
            }
            else
            {
                throw new ArgumentException("无效的操作命令： {0}", operate);
            }
        }

    }
}
